import { makeAutoObservable } from 'mobx'
import { history } from 'umi'
import { getData, postData, putData } from '@/servers/http'
import { api } from '@/servers/api'

interface Generate {
    match_status: string
    match_reason: string
    next_action: string
}

class Store {
    professionsInfo: any = {}
    quickAcceptList = ['企业文化满意']
    quickRejectList = ['休假不合适', '职位要求不匹配']

    constructor() {
        makeAutoObservable(this)
    }

    /** 获取岗位匹配记录 */
    getProfessionsInfo = () => {
        const { code } = history.location.query || {}

        getData(`${api.professionsInfo}`, { code }).then(({ status, data }) => {
            if (status === 200 && data) {
                this.professionsInfo = data
            }
        })
    }
    generateMatchTable = async (params: Generate) => {
        const { dossierId, code } = history.location.query || {}

        const finishRes = await getData(`${api.userBarriersIsFinish}${dossierId}`)

        /** 已完成 使用PUT */
        if (finishRes.data.is_finish === '1') {
            putData(`${api.userBarriersBatchUpdate}${dossierId}`, { fill_type: 3, code, ...params }).then(({ status, data }) => {
                if (status === 200 && data) {
                    history.go(-2)
                }
            })
            return
        }

        postData(`${api.userBarriersBatchInput}${dossierId}`, { fill_type: 3, code, ...params }).then(({ status, data }) => {
            if (status === 200 && data) {
                history.go(-2)
            }
        })
    }
}
export default Store
